<!--
 * @Author: Haochen
 * @Date: 2021-12-08 14:59:49
 * @LastEditTime: 2021-12-11 21:50:34
 * @FilePath: \students-system\src\views\subjects\AddSubject.vue
-->
<template>
  <div>
    <h4>新增专业</h4>
    <br />
    <el-input type="text" v-model.lazy="newSubject.name" />
    <el-button type="primary" @click="addNewSubject">确认新增</el-button><br />
  </div>
</template>

<script>
import Pages from '../../components/common/Pages.vue';

export default {
  data() {
    return {
      newSubject: {},
      pageData: { currentPage: 1, pageSize: 3 },
      searchData: { value: '' },
    };
  },
  created() {},
  methods: {
    async addNewSubject() {
      const { data: res } = await this.$api.subjects.addNewSubject(
        this.newSubject
      );
      if (res.code) {
        alert(res.message);
        this.newSubject = {};
      }
    },

    confirmSearch() {
      this.getSubjects();
      this.pageData.currentPage = 1;
    },

    // * 下一页功能
    nextPage() {
      if (this.pageData.currentPage < this.pages) {
        this.pageData.currentPage++;
      }
    },

    // * 上一页功能
    prevPage() {
      if (this.pageData.currentPage > 1) {
        this.pageData.currentPage--;
      }
    },
    // * 首页功能
    firstPage() {
      this.pageData.currentPage = 1;
    },
    // * 尾页功能
    lastPage() {
      this.pageData.currentPage = this.pages;
    },
  },
  watch: {
    pageData: {
      deep: true,
      handler() {
        this.getSubjects();
      },
    },
  },
  components: { Pages },
};
</script>

<style>
.el-input {
  margin-bottom: 20px;
}
</style>
